package com.training.permission.action.chengshu;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.training.permission.service.chengshu.IPermissionService;
import com.training.pojo.chengshu.URole;
import com.training.pojo.chengshu.UUser;
import com.training.pojo.chengshu.UserRole;

@SuppressWarnings("serial")
public class UpdatePerToUserAction extends ActionSupport {
	private IPermissionService permissionService;
	private UUser listUser;
	private List<URole> listRole;
	private URole urole;
	private UserRole role;
	private String id;
	private String name;
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public UserRole getRole() {
		return role;
	}

	public void setRole(UserRole role) {
		this.role = role;
	}

	public URole getUrole() {
		return urole;
	}

	public void setUrole(URole urole) {
		this.urole = urole;
	}

	public List<URole> getListRole() {
		return listRole;
	}

	public void setListRole(List<URole> listRole) {
		this.listRole = listRole;
	}

	public UUser getListUser() {
		return listUser;
	}

	public void setListUser(UUser listUser) {
		this.listUser = listUser;
	}

	public void setPermissionService(IPermissionService permissionService) {
		this.permissionService = permissionService;
	}

	public String execute(){
		System.out.println("打印");
		System.out.println(role.getUUser().getUid()+":::"+role.getURole().getRoleid());
		if(permissionService.updateUserRole(role)){
			listUser.setUid(Integer.parseInt(id));
			listUser.setUname(name);
			urole = permissionService.queryRoleId(role.getUUser().getUid());
			listRole = permissionService.listRole(role.getUUser().getUid());
			this.addFieldError("updateInformation", "修改成功！");
			return SUCCESS;
		}else{
			listUser.setUid(Integer.parseInt(id));
			listUser.setUname(name);
			urole = permissionService.queryRoleId(role.getUUser().getUid());
			listRole = permissionService.listRole(role.getUUser().getUid());
			this.addFieldError("updateInformation", "修改失败！");
			return SUCCESS;
		}
		
	}
	public String showInfor(){
		System.out.println(id);
		listUser = new UUser();
		System.out.println("节点");
		listUser.setUid(Integer.parseInt(id));
		listUser.setUname(name);
		urole = permissionService.queryRoleId(listUser.getUid());
		//System.out.println(urole.getRoleid()+"hhhhhhhhhhh"+urole.getRolename());
		listRole = permissionService.listRole(listUser.getUid());
		return INPUT;
	}
}
